package com.xinke.component.common.util.sno;

import com.xinke.component.common.config.SnowFlake;

/**
 * @Author yzx
 * @CreateTime 2025/3/23 16:20
 * @Version 1.0
 * @Description:    ID生成工具类
 */
public class IdGen {
    private static volatile SnowFlake instance = SnowFlake.getInstance();
    private static long DEFAULT_DATACENTER_ID = 0L;
    private static long DEFAULT_MACHINE_ID = 0L;
    private IdGen() {}

    /**
     * 获取下一个ID
     */
    public static long nextId() {
        if (instance == null) {
            throw new IllegalStateException("SnowflakeIdGenerator not initialized! Call initialize() first.");
        }
        return instance.nextId();
    }

    public static String nextId(String perfix) {
        if (instance == null) {
            throw new IllegalStateException("SnowflakeIdGenerator not initialized! Call initialize() first.");
        }
        return perfix + instance.nextId();
    }

}
